﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AplicacionMVC.Controllers
{
    public class RecursoController : Controller
    {
        RecursosWS.RecursoClient proxy = new RecursosWS.RecursoClient();

        //
        // GET: /Sede/
        public ActionResult Index()
        {
            return View(proxy.ListarRecurso());
        }

        //
        // GET: /Sede/Details/5
        public ActionResult Details(int id)
        {
            return View(proxy.ObtenerRecurso(id));
        }

        //
        // GET: /Sede/Create
        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Sede/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                string nombre = (string)collection["Nombre"];
                string estado = (string)collection["Estado"];
                //int sede = int.Parse(collection["Sede.Codigo"]);
                proxy.CrearRecurso(nombre, Convert.ToChar(estado));
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Sede/Edit/5 
        public ActionResult Edit(int id)
        {
            return View(proxy.ObtenerRecurso(id));
        }

        //
        // POST: /Sede/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                string nombre = (string)collection["Nombre"];
                string correo = (string)collection["Correo"];
                string estado = (string)collection["estado"];
                //int sede = int.Parse(collection["Sede.Codigo"]);
                proxy.ModificarRecurso(id, nombre, Convert.ToChar(estado));
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Sede/Delete/5 
        public ActionResult Delete(int id)
        {
            return View(proxy.ObtenerRecurso(id));
        }

        //
        // POST: /Sede/Delete/5
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                proxy.EliminarRecurso(id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

    }
}
